package com.qf.common.configure;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: claud
 * @Date: 2018/8/16 14 33
 * @Description: 用于记录各个资源的代理信息的类
 */

@Slf4j
@Data
public class ProxyInfo {

    private String userName;
    private String password;
    private String proxy;
    private String ip;
    private String port;
    private String switchType;
    private String loginUrl;
    private String webId;
    private int timeout;

    /**
     * 通过session获取相应的代理信息
     */
//    public static ProxyInfo getProxy(HttpSession session, int proxyId){
//        Integer gid = 0;
//        Map<Integer,ProxyInfo> proxyMap = (Map<Integer,ProxyInfo>)session.getAttribute("proxyMap");
//        if(proxyMap==null){
//            gid = UserUtil.getUserGidUnloginDeny();
//            if(gid!=null&&gid!=0) {
//                proxyMap = fetchResourceProxy(gid);
//                session.setAttribute("proxyMap", proxyMap);
//            }
//        }
//        ProxyInfo pi = proxyMap.get(proxyId);
//        //chkd的默认为账号类型
//        if(pi!=null&&proxyId==14&&pi.getSwitchType()==null){
//            pi.setSwitchType("0");
//        }
//        //万方医学默认为账号类型.
//        if(pi!=null&&proxyId==16&&pi.getSwitchType()==null){
//            pi.setSwitchType("0");
//        }
//        log.info_old("当前单位id:"+gid+"--代理数量:"+proxyMap.size()+"--资源id:"+proxyId+"--代理内容:"+pi.toString());
//        return pi;
//    }
    public ProxyInfo(String userName, String password, String switchType) {
        this.userName = userName;
        this.password = password;
        this.switchType = switchType;
    }

    public ProxyInfo() {
        this.port = "10086";
        this.userName = "qf";
        this.password = "qf3.1415";
        this.switchType = "1";
    }

    public static void main(String[] args) {
//        Map<Integer, ProxyInfo> map = fetchResourceProxy(1);
//        log.info_old(map.size());
    }

    /**
     * 下面的方法都是用来测试的
     */
    public static ProxyInfo getSichuanIpProxy() {
        ProxyInfo pi = new ProxyInfo();
        pi.setIp("111.231.192.250");
        return pi;
    }

    public static ProxyInfo getFudanIpProxy() {
        ProxyInfo pi = new ProxyInfo();
        pi.setIp("101.231.201.107");
        return pi;
    }

    //
    public static ProxyInfo getShangjiaoIpProxy() {
        ProxyInfo pi = new ProxyInfo();
        pi.setIp("202.120.23.59");
//        pi.setSwitchType("2");
        return pi;
    }

    public static ProxyInfo getgcrIpProxy() {
        ProxyInfo pi = new ProxyInfo();
        pi.setIp("127.0.0.1");
        pi.setPort("10809");
//        pi.setSwitchType("2");
        return pi;
    }

    public static ProxyInfo getGuangzhouProxy() {
        ProxyInfo pi = new ProxyInfo();
        pi.setIp("210.38.102.157");
        return pi;
    }

    ;

    public static ProxyInfo getCnkiAccountProxy() {
        ProxyInfo pi = new ProxyInfo();
        String account = "lyzyyy";
        String pwd = "tsg123";
        pi.setUserName(account);
        pi.setPassword(pwd);
        pi.setSwitchType("0");
        return pi;
    }

    public static ProxyInfo getCnkiAccountNoLimitProxy() {
        ProxyInfo pi = new ProxyInfo();
        String account = "xn0086";
        String pwd = "cdd3yy";
        pi.setUserName(account);
        pi.setPassword(pwd);
        pi.setSwitchType("0");
        return pi;
    }

    /**
     * ip免代理形式
     */
    public static ProxyInfo getWfIpProxy() {
        ProxyInfo pi = new ProxyInfo();
//        pi.setIp("202.120.23.59");
        pi.setIp("101.231.201.107"); //复旦大学
//        pi.setIp("202.195.214.11"); //南京中医药大学
        pi.setUserName("qf");
        pi.setPassword("qf3.1415");
        pi.setPort("10086");
        pi.setSwitchType("1");
        return pi;
    }

    /**
     * 下载扣钱的万方卡形式
     */
    public static ProxyInfo getWfAccountProxy() {
        ProxyInfo pi = new ProxyInfo();
        String account = "lyzyyy";
        String pwd = "lyzyyy123";
        pi.setUserName(account);
        pi.setPassword(pwd);
        pi.setSwitchType("0");
        return pi;
    }

    /**
     * 万方下下载无限制账号
     */
    public static ProxyInfo getWfAccountNoLimitProxy() {
        ProxyInfo pi = new ProxyInfo();
        String account = "qksyy9";
        String pwd = "718978";
        pi.setUserName(account);
        pi.setPassword(pwd);
        pi.setSwitchType("0");
        return pi;
    }

    /**
     * 中日的ip有万方医学的权限.
     */
    public static ProxyInfo getZhongriIpProxy() {
        ProxyInfo pi = new ProxyInfo();
        pi.setIp("47.95.220.101");
        String loginUrl = "http://login.med.wanfangdata.com.cn/Account/LogOnByUrl?sign=U35ecVAsVW5Vfgd6BFsCeF4nCWoJfQd9UzIBNwY0DGVSMFox";
        pi.setLoginUrl(loginUrl);
        return pi;
    }

    public static ProxyInfo getHuaianChkdNoLimitAccountProxy() {
        ProxyInfo pi = new ProxyInfo();
        String account = "hadyrmyy";
        String pwd = "hayy0501";
        pi.setUserName(account);
        pi.setPassword(pwd);
        pi.setSwitchType("0");
        return pi;
    }

    public static ProxyInfo getHuaianChkdChargeAccountProxy() {
        ProxyInfo pi = new ProxyInfo();
        String account = "pdxqrmyy";
        String pwd = "rmyy123";
        pi.setUserName(account);
        pi.setPassword(pwd);
        pi.setSwitchType("0");
        return pi;
    }

    public static ProxyInfo getWfmedHuaianNolimitAccountProxy() {
        ProxyInfo pi = new ProxyInfo();
        String account = "hadyrmyy";
        String pwd = "hadyrmyy6666";
        pi.setUserName(account);
        pi.setPassword(pwd);
        pi.setSwitchType("0");
        return pi;
    }

    public static ProxyInfo getWfmedWuxiCashAccountProxy() {
        ProxyInfo pi = new ProxyInfo();
        String account = "wxsytsg";
        String pwd = "456123";
        pi.setUserName(account);
        pi.setPassword(pwd);
        pi.setSwitchType("0");
        return pi;
    }


//    private static Map<Integer, ProxyInfo> fetchResourceProxy(Integer gid){
//        Map<Integer, ProxyInfo> map=new HashMap<>();
//        try {
//            //	log.info_old(gid+"      "+nid);
//            Connection c= DBUtil.getConnection();
//            String sql="select * from navigation_group where gid =?;";
//            PreparedStatement p;
//            p=c.prepareStatement(sql);
//            p.setInt(1, gid);
//            ResultSet rs=p.executeQuery();
//            while(rs.next()){
//                //		log.info_old(rs.getString("username"));
//                String userName = rs.getString("username");
//                String password = rs.getString("password");
//                String proxy = rs.getString("proxy");
//                if(!StrUtil.isEmpty(proxy)){
//                    proxy = proxy.trim();
//                }
//                String switchType = rs.getString("switch_type");
//                String loginUrl = rs.getString("login_url");
//                String webId = rs.getString("webid");
//                ProxyInfo pi = new ProxyInfo();
//                pi.setUserName(userName);
//                pi.setPassword(password);
//                pi.setProxy(proxy);
//                if(proxy!=null&&proxy!=""&&proxy.contains(":")){
//                    pi.setIp(proxy.split(":")[0]);
//                    pi.setPort(proxy.split(":")[1]);
//                }
//                pi.setLoginUrl(loginUrl);
//                pi.setSwitchType(switchType);
//                pi.setWebId(webId);
//                Integer nid = rs.getInt("nid");
//                map.put(nid,pi);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }finally{
//            DBUtil.closeConnection();
//        }
//        return map;
//    }


}
